
/**

jsShapelib
Author: Addy Osmani
Release: 1.0.1
Date: Thursday, 30 Sept 2010.
Released under the MIT license.


**/



/*
   drawCircle() 
   selector : a jQuery selector defining an element or array of elements
   center : the center of the circle
   radius : the radius of the circle
   angle: the angle of the circle
   x: the left offset of all points on the circle
   y: the top offset of all points on the circle
   
   Sample usage: 
   CSS: .box { background-color:red; height:90px; width:90px;  position:absolute; margin:5px;}
   JS:drawCircle('.box', 50, 200, 90, 310, 220);
   
*/
function drawCircle(selector)
{
    var   FRIENDS_PER_CIRCLE    =14;
    $(selector).each(function(index)
    {
       
        var a = 2*Math.PI/FRIENDS_PER_CIRCLE*index;
        var R = 63;
        var x = Math.sin(a)*R;
        var y = -Math.cos(a)*R;       
        var pointx  =  x - 14
        var pointy  = y - 14		
		
        $(this).css('margin-left', pointx +  'px');
        $(this).css('margin-top', pointy  +  'px');
    });
    
}





/*
   drawEllipse()
   selector : a jQuery selector defining an element or array of elements
   x: the left offset of all points on the ellipse
   y: the top offset of all points on the ellipse
   a: the height of the ellipse
   b: the width of the ellipse
   angle: the angle of the ellipse
   
   Sample usage: 
   CSS: .box { background-color:red; height:60px; width:60px;  position:absolute; margin:5px;}
   JS:drawEllipse(".box", 230,300, 200, 350, 360);
   
*/

function drawEllipse(selector, x, y, a, b, angle)
{
    var steps = $(selector).length;
        
    var i = 0;
    var beta = -angle * (Math.PI / 180);    
    var sinbeta = Math.sin(beta);
    var cosbeta = Math.cos(beta);
        
    $(selector).each(function(index)
    {
        i+= (360/steps);
        var alpha = i * (Math.PI / 180) ;
        var sinalpha = Math.sin(alpha);
        var cosalpha = Math.cos(alpha);
        var X = x + (a * cosalpha * cosbeta - b * sinalpha * sinbeta);
        var Y = y + (a * cosalpha * sinbeta + b * sinalpha * cosbeta);
        
        
        X = Math.floor(X);
        Y = Math.floor(Y);
        
        $(this).css('margin-top', X + 'px');
        $(this).css('margin-left', Y + 'px');
        
    });
        
        
       
}


